package com.example.netease.dao;

import com.example.netease.entity.Button;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * ( button)表数据库访问层
 *
 * @author makejava
 * @since 2022-05-08 16:28:01
 */
@Mapper
public interface ButtonDao {

//    /**
//     * 通过ID查询单条数据
//     *
//     * @param id 主键
//     * @return 实例对象
//     */
//     Button queryById(Integer id);

     @Select("select * from button")
     List<Button> selectList();



    /**
     * 新增数据
     *
     * @param  button 实例对象
     * @return 影响行数
     */
    @Insert("insert into  button(btn, content,font_color,frame_color,background_color)\n" +
            "values (#{btn}, #{content},#{fontColor}, #{frameColor},#{backgroundColor})")
    int insert( Button button);



    /**
     * 修改数据
     *
     * @param  button 实例对象
     * @return 影响行数
     */
//    @Update("<script>",
//            "update button <set>",
//            "<if test=\"btn != null and btn!= ''\ ">btn = #{btn}</if>",
//            "<if test="age != null and age != '' ">age= #{age}</if></set>",
//            "where id = #{id}</script>")
//    int updateById(Integer id);
    @Update("<script>" +
            " update button " +
            "<set>\n" +
            "            <if test=\"btn != null and btn != ''\">\n" +
            "                btn = #{btn},\n" +
            "            </if>\n" +
            "            <if test=\"content != null and content != ''\">\n" +
            "                content = #{content},\n" +
            "            </if>\n" +
            "            <if test=\"fontColor != null and fontColor != ''\">\n" +
            "                font_color = #{fontColor},\n" +
            "            </if>\n" +
            "            <if test=\"frameColor != null and frameColor != ''\">\n" +
            "                frame_color = #{frameColor},\n" +
            "            </if>\n" +
            "            <if test=\"backgroundColor != null and backgroundColor != ''\">\n" +
            "                background_color = #{backgroundColor},\n" +
            "            </if>\n" +
            "</set> \n" +
            "        where id = #{id}" +
            "</script>")
    int update( Button button);

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 影响行数
     */
    @Delete("delete from  button where id = #{id}")
    int deleteById(Integer id);

}

